package io.renren.modules.eas.service.impl;

import io.renren.modules.eas.entity.EasBasicEduEntity;
import io.renren.modules.eas.entity.EasBasicEduthemeEntity;
import io.renren.modules.eas.entity.EasEduthemeAspectEntity;
import io.renren.modules.eas.service.EasBasicEduService;
import io.renren.modules.eas.service.EasBasicEduthemeService;
import io.renren.modules.eas.service.EasEduthemeAspectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.eas.dao.EasCommentKeysDao;
import io.renren.modules.eas.entity.EasCommentKeysEntity;
import io.renren.modules.eas.service.EasCommentKeysService;
import org.springframework.util.ObjectUtils;


@Service("easCommentKeysService")
public class EasCommentKeysServiceImpl extends ServiceImpl<EasCommentKeysDao, EasCommentKeysEntity> implements EasCommentKeysService {

    @Autowired
    EasBasicEduService easBasicEduService;
    @Autowired
    EasBasicEduthemeService easBasicEduthemeService;

    @Autowired
    EasEduthemeAspectService easEduthemeAspectService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<EasCommentKeysEntity> page = this.page(
                new Query<EasCommentKeysEntity>().getPage(params),
                new QueryWrapper<EasCommentKeysEntity>()
                        .eq(!ObjectUtils.isEmpty(params.get("status")),"status",params.get("status"))
                        .eq(!ObjectUtils.isEmpty(params.get("type")),"type",params.get("type"))
        );
        if (params.containsKey("showName")){
            for (EasCommentKeysEntity record : page.getRecords()) {
                EasBasicEduEntity eduEntity = easBasicEduService.getById(record.getEducationId());
                record.setEducationName(eduEntity.getEducationName());
                EasBasicEduthemeEntity easBasicEdutheme = easBasicEduthemeService.getById(record.getEduthemeId());
                record.setEduthemeName(easBasicEdutheme.getFactor());
                EasEduthemeAspectEntity aspectEntity = easEduthemeAspectService.getById(record.getEduaspectId());
                record.setEduaspectName(aspectEntity.getAspect());
            }
        }
        return new PageUtils(page);
    }

    @Override
    public List<Map> selectGroupKeys() {
      return  baseMapper.selectGroupKeys();
    }

    @Override
    public List<Map> keysByCreate(Long userId) {
        return baseMapper.selectGroupKeysByCreate(userId);
    }

}
